<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="./js/jquery-2.1.0.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/Global.js"></script>
    <style>
        .wrap {
            padding: 20px;
            width: 100%;
            overflow: auto;
            box-sizing: border-box;
        }

        ul {
            width: 100%;
        }

        ul li {
            width: 25%;
            float: left;
            height: 36px;
            line-height: 36px;
            /* background: #ccc; */
            text-align: center;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-top: 0px;
            cursor: pointer;
        }

        ul li:first-of-type {
            border: 1px solid #ccc;
        }

        ul li:nth-of-type(2) {
            border: 1px solid #ccc;
            border-left: 0px;

        }

        ul li:nth-of-type(3) {
            border: 1px solid #ccc;
            border-left: 0px;

        }

        ul li:nth-of-type(4) {
            border: 1px solid #ccc;
            border-left: 0px;

        }

        .winbody {
            padding: 10px;
            display: none;
        }

        .carlist {
            width: 120px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            font-size: 14px;
            display: inline-block;
        }

        .tabs {
            /* width: 900px; */
        }

        .tabs a {
            width: 120px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            font-size: 14px;
            display: inline-block;
        }
        .layui-form {
            display: inline-block;
            margin: 0;
            padding: 0;
            height: 24px;
        }

        .search {
            width: 200px;
            height: 38px;
            margin: 0 auto;
            display: inline-block;
            padding-top: 1px;

        }

        .search .layui-input {
            width: 200px;
        }

    </style>
</head>

<body>
    <div class="wrap">
        <div style="text-align:center;">

            <div class="search">
                <input class="layui-input ksdate" type="text" placeholder="开始日期">
            </div>
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-input-inline">
                        <select lay-filter="datesel" name="quiz2">
                            <option value="">请选时段</option>
                            <option value="0">一季度</option>
                            <option value="1">二季度</option>
                            <option value="2">三季度</option>
                            <option value="3">四季度</option>
                            <option value="4">上半年</option>
                            <option value="5">下半年</option>
                            <option value="6">本年度</option>
                            <option value="7">上年度</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="search">
                <input class="layui-input jsdate" type="text" placeholder="结束日期">
            </div>
            <div class="search">
                <button class="layui-btn layui-btn-normal" onclick="sel()">查询</button>
            </div>
        </div>

        <div class="layui-btn layui-btn-sm" onclick="add()">添加</div>
        <table class="layui-table">
            <thead>
                <tr>

                    <th rowspan="2">
                        序号
                    </th>
                    <th rowspan="2">
                        时间
                    </th>
                    <th rowspan="2">
                        车辆牌号
                    </th>
                    <th rowspan="2">
                        司机姓名
                    </th>
                    <th>
                        汽油
                    </th>
                    <th>
                        柴油
                    </th>
                    <th>
                        单价
                    </th>
                    <th>
                        金额
                    </th>

                </tr>
                <tr>
                    <th class="qprice">0</th>
                    <th class="cprice">0</th>
                    <th class="dprice">0</th>
                    <th class="zprice">0</th>
                </tr>
            </thead>
            <tbody class="jiayou">

            </tbody>
        </table>
    </div>
    <div class="winbody">
        <table class="layui-table">
            <thead>
                <tr>
                    <th>
                        时间
                    </th>
                    <th>车辆牌号</th>
                    <th>司机</th>
                    <th>汽油(元)</th>
                    <th>柴油(元)</th>
                    <th>单价</th>
                </tr>
            </thead>
            <tbody>
                <tr class="add">
                    <td><input type="text" data-name="refDt" class="layui-input sj" value=""></td>
                    <td><input type="text" data-name="refCarNumber" class="layui-input" value=""></td>
                    <td><input type="text" data-name="refDriver" class="layui-input" value=""></td>
                    <td><input type="text" data-name="refGasoline" class="layui-input" value=""></td>
                    <td><input type="text" data-name="refDiesel" class="layui-input" value=""></td>
                    <td><input type="text" data-name="refPrice" class="layui-input" value=""></td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
<script>
layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '.ksdate' //指定元素
        });
        laydate.render({
            elem: '.jsdate' //指定元素
        });
    });
    layui.use('form', function () {
        var form = layui.form
        form.on('select(datesel)', function (data) {
            let val = data.value
            let years = new Date().getFullYear()
            switch (val) {
                case '0':
                    $('.ksdate').val(`${years}-01-01`)
                    $('.jsdate').val(`${years}-03-31`)
                    break;
                case '1':
                    $('.ksdate').val(`${years}-04-01`)
                    $('.jsdate').val(`${years}-06-30`)
                    break;
                case '2':
                    $('.ksdate').val(`${years}-07-01`)
                    $('.jsdate').val(`${years}-09-30`)
                    break;
                case '3':
                    $('.ksdate').val(`${years}-10-01`)
                    $('.jsdate').val(`${years}-12-31`)
                    break;
                case '4':
                    $('.ksdate').val(`${years}-01-01`)
                    $('.jsdate').val(`${years}-06-30`)
                    break;
                case '5':
                    $('.ksdate').val(`${years}-07-01`)
                    $('.jsdate').val(`${years}-12-31`)
                    break;
                case '6':
                    $('.ksdate').val(`${years}-01-01`)
                    $('.jsdate').val(`${years}-12-31`)
                    break;
                    case '7':
                    $('.ksdate').val(`${years-1}-01-01`)
                    $('.jsdate').val(`${years-1}-12-31`)
                    break;
            }
        });
    })
</script>
<script>

    function sel () {
        let data = {
            custId:loadUserInfo.customer.id,
            startTime:$('.ksdate').val(),
            endTime:$('.jsdate').val()
        }
        $.ajax({
        url: `${API}/erpRefueling/getrefuelingIdbPage`,
        type: 'post',
        data:data,
        success: function (res) {
            let str = ''
            let arr = res.data.reverse()
            let qprice = 0
            let cprice = 0
            let dprice = 0
            let zprice = 0
            $.each(arr,function (i,json) {
                if (json.refGasoline) {
                    qprice+= json.refGasoline
                }
                if (json.refDiesel) {
                    cprice+= json.refDiesel
                }
                if (json.refPrice) {
                    dprice+= json.refPrice
                }
                if (json.refTotal) {
                    zprice+= json.refTotal
                }
                str += `<tr><td>${arr.length - i }</td>
                <td>${json.refDt == null ? '' : json.refDt}</td>
                <td>${json.refCarNumber == null ? '' : json.refCarNumber}</td>
                <td>${json.refDriver == null ? '' : json.refDriver}</td>
                <td>${json.refGasoline == null ? '' : json.refGasoline}</td>
                <td>${json.refDiesel == null ? '' : json.refDiesel}</td>
                <td>${json.refPrice == null ? '' : json.refPrice}</td>
                <td>${json.refTotal == null ? '' : json.refTotal}</td>
                </tr>`
            })
            $('.jiayou').html(str)
            $('.qprice').html(qprice.toFixed(2))
            $('.cprice').html(cprice.toFixed(2))
            $('.dprice').html(dprice.toFixed(2))
            $('.zprice').html(zprice.toFixed(2))
        }
    })
    
    }
    sel()
    let layer = ''
    layui.use('layer',function () {
        layer = layui.layer
    })
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '.sj'
        });
    })
    function add() {
        layui.use('layer', function () {
            let layer = layui.layer;
            layer.open({
                type: 1,
                content: $('.winbody'),
                title: '添加',
                area: ['720px'],
                btn: ['保存', '取消'],
                maxmin: true,
                yes: function () {
                    let data = {
                        customerId:loadUserInfo.customer.id
                    }
                    $('.add input').each(function () {
                        data[$(this).data('name')]=$(this).val()
                    })

                    $.ajax({
                        url: `${API}/erpRefueling/inertOrUpdaterefuelingId`,
                        type: 'post',
                        data:data,
                        success: function (res) {
                            if(res.code == 0) {
                                layer.msg('添加成功!')
                            window.location.reload()
                            }
                        }
                    })

                }
            })
        });
    }
    function save() {

    }

</script>